package com.supinfo.sun.sungamers.gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import com.supinfo.sun.sungamers.gui.listeners.PlayActionListener;

/**
 * @author Liu, Bing(Locke)
 * @since 2011-6-5
 * @version 0.3
 */
public class SunGamerFrame extends JFrame {
	
	private JLabel label1;
	private JLabel label2;
	private JPanel gamePanel;
	private JPanel levelPanel;
	private JRadioButton radioBtnNumGame;
	private JRadioButton radioBtnCapGame;
	private ButtonGroup btnGroupGame;
	private JRadioButton radioBtnEasy;
	private JRadioButton radioBtnMedium;
	private JRadioButton radioBtnHard;
	private ButtonGroup btnGroupLevel;
	private JButton btnPlay;
	private JMenuBar menuBar;
	private JMenu menuPerson;
	private JMenuItem menuItemPerson;
	private ResourceBundle myBundle;
	
	public SunGamerFrame() {
		myBundle = ResourceBundle.getBundle("com.supinfo.sun.sungamers.lang.sungame");
		
		// define the size of the frame
		this.setSize(310, 250);
		
		this.setLocationRelativeTo(null);
		
		// define the title of the frame
		this.setTitle("SunGamer");
		
		// define the default operation when
		// the frame is closed
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.setLayout(null);
		
		menuBar = new JMenuBar();
		this.setJMenuBar(menuBar);
		
		menuPerson = new JMenu(myBundle.getString("persons"));
		menuBar.add(menuPerson);
		
		menuItemPerson = new JMenuItem(myBundle.getString("listPersons"));
		menuPerson.add(menuItemPerson);
		menuItemPerson.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				new ListPersonsFrame();
			}
		});
		
		label1 = new JLabel(myBundle.getString("chooseGame"));
		Dimension labelSize1 = label1.getPreferredSize();
		label1.setBounds(5, 5, labelSize1.width, labelSize1.height);
		this.add(label1);
		
		gamePanel = new JPanel();
		gamePanel.setLayout(new FlowLayout());
		
		radioBtnNumGame = new JRadioButton(myBundle.getString("numberFinderGame"));
		radioBtnNumGame.setSelected(true);
		radioBtnNumGame.setActionCommand(myBundle.getString("playNumberFinderGame"));
		
		radioBtnCapGame = new JRadioButton(myBundle.getString("capitalFinderGame"));
		btnGroupGame = new ButtonGroup();
		btnGroupGame.add(radioBtnNumGame);
		btnGroupGame.add(radioBtnCapGame);
		this.add(radioBtnNumGame);
		this.add(radioBtnCapGame);
		
		gamePanel.add(radioBtnNumGame);
		gamePanel.add(radioBtnCapGame);
		
		Dimension gamePanelSize = radioBtnCapGame.getPreferredSize();
		gamePanel.setBounds(5, 25, new Double(2.2 * gamePanelSize.width).intValue(), (3 + gamePanelSize.height));

		this.add(gamePanel);
		
		label2 = new JLabel(myBundle.getString("chooseDiffLevel"));
		Dimension labelSize2 = label2.getPreferredSize();
		label2.setBounds(5, 55, labelSize2.width, labelSize2.height);
		this.add(label2);
		
		levelPanel = new JPanel();
		levelPanel.setLayout(new GridLayout(3, 1));
		
		radioBtnEasy = new JRadioButton(myBundle.getString("easy"));
		radioBtnEasy.setSelected(true);
		radioBtnMedium = new JRadioButton(myBundle.getString("medium"));
		radioBtnHard = new JRadioButton(myBundle.getString("hard"));
		
		btnGroupLevel = new ButtonGroup();
		btnGroupLevel.add(radioBtnEasy);
		btnGroupLevel.add(radioBtnMedium);
		btnGroupLevel.add(radioBtnHard);
		levelPanel.add(radioBtnEasy);
		levelPanel.add(radioBtnMedium);
		levelPanel.add(radioBtnHard);
		
		Dimension levelPanelSize = radioBtnMedium.getPreferredSize();
		levelPanel.setBounds(10, 80, levelPanelSize.width, new Double(3.1 * levelPanelSize.height).intValue());
		this.add(levelPanel);
		
		btnPlay = new JButton(myBundle.getString("play"));
		Dimension btnPlaySize = btnPlay.getPreferredSize();
		btnPlay.setBounds(5, 140, btnPlaySize.width, btnPlaySize.height);
		this.add(btnPlay);
		this.setVisible(true);
		
		btnPlay.addActionListener(new PlayActionListener(this));
	}

	public JLabel getLabel1() {
		return label1;
	}

	public JLabel getLabel2() {
		return label2;
	}

	public JPanel getGamePanel() {
		return gamePanel;
	}

	public JPanel getLevelPanel() {
		return levelPanel;
	}

	public JRadioButton getRadioBtnNumGame() {
		return radioBtnNumGame;
	}

	public JRadioButton getRadioBtnCapGame() {
		return radioBtnCapGame;
	}

	public ButtonGroup getBtnGroupGame() {
		return btnGroupGame;
	}

	public JRadioButton getRadioBtnEasy() {
		return radioBtnEasy;
	}

	public JRadioButton getRadioBtnMedium() {
		return radioBtnMedium;
	}

	public JRadioButton getRadioBtnHard() {
		return radioBtnHard;
	}

	public ButtonGroup getBtnGroupLevel() {
		return btnGroupLevel;
	}

	public JButton getBtnPlay() {
		return btnPlay;
	}
	
}
